# class 类关键字
# Student 类名
# (object) (继承类)

# 特殊变量
__author__ = 'zhangsan'
__doc__ = '文档'
__name__ = '名字'

# 公开变量
def test():
    print("测试")

# 非公开变量
# _xxx和__xxx这样的函数或变量就是非公开的（private），不应该被直接引用，比如_abc，__abc等；
_author : 'zhangsan'
__str:"字符串"

# 定义类
class Person(object):

    # 构造函数（初始化函数，用于创建类的实例）
    def __init__(self,name):
        self.name = name

    def print_name(self):
        print('%s' %(self.name) )

# 实例化
# 使用了__init__ 必须传入参数
user= Person("zhangsan")
print(user.name)

class ManPerson(Person):
    def __init__(self,age,name):
        super().__init__(name)  
        self.age = age

    def work(self):
        print('%s is working' %(self.name) )

class WoPeron(Person):
    def sing(self):
        print('%s is singing' %(self.name))

man = ManPerson(123, "zhangsna")
man.print_name()
man.work()

woMan=  WoPeron("lisi")
woMan.print_name()
woMan.sing()    

subMan = ManPerson(user,"chenghu")
subMan.print_name()

# 获取对象信息
import types
if type(subMan) == types.new_class:
    print("是类")
else:
    print("不是类")

if isinstance(subMan, ManPerson):
    print("isinstance是类")
else:
    print("isinstance不是类")

# 获取对象的所有属性和方法
print("获取属性--",dir(subMan)) 
if hasattr(subMan,"name"):
    nameAttr = getattr(subMan,"name")
    print(nameAttr)
else:
    print("没有name属性")

